<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function add(x,y){

            return x+y
        }
        function minus(x,y){
            return x-y
        }

        var pow = function(x,y){
            return x**y
        }

        function pow(x,y){
            return x**y
        }

        function sqrt(){
            var x=1;
            console.log(x)
            console.log(global)
            return x
        }
        var global = '全局变量'
        // console.log(x)

        var foo = function(j){
            console.log(j)
        }
        //foo('形参')
        //console.log(j)
        //参数默认值
        function showInfo(info){
            // if(!info){
            //     info = "查无此人"
            // }
            // if(info == undefined){
            //     info = "查无此人"
            // }
            info = info == undefined ? "查无此人" : info

            console.log(info)
        }
        // showInfo('abc')

        function showInfo2(info="查无此人"){
            console.log(info)
        }

        
        function showUser(obj){
            console.log(obj.name)
            console.log(obj.age)
            var str = `我叫${obj.name}，年龄${obj.age}`
            return str
        }
        var obj = {name:'马云',age:55}
        var res = showUser(obj)
        console.log(res)
        arr = [1,2,3,4]
        //arr.splice(1,1,'a','b')
        function sum(){
           var res = 0
            Array.from(arguments).forEach(function(el){
                res += el
            })
            return res
        }
        //arry.splice(idx,cout,....)
        function baz(x,y){
            var res = x * y
            var sum = 0
            for(var i=2;i<arguments.length;i++){
                sum += arguments[i]
            }

            console.log(arguments)
            return res + sum

        }

        baz(2,3,1,2)
        //2*3 + 1 + 2
        

    </script>
</body>
</html>